//jQuery.noConflict();

(function($) {
	// toolbar action
	$('#btn_save').click(function () { $('#edit-form').submit(); });
	$('#btn_save_edit').click(function () { 
		var action = $('#edit-form').attr('action');
		action += '/contEdit/1';
		$('#edit-form').attr('action', action);
		$('#edit-form').submit(); 
	});
	$('#btn_delete').click(function (e) { 
		if(!confirm('Are you sure to delete this item?')) return false;

		var url = $(this).attr('href').replace(/delete\/.*/, 'index');
		var button = $(this);
		button.button('loading');
		$.post(this.href, function(data) {
			button.button('reset');
			window.location=url;
		});
		return false;
	});
	
	// grid delete link
	$('.btn_delete').click(function (e) { 
		if(!confirm('Are you sure to delete this item?')) return false;

		var url = $(this).attr('href').replace(/delete\/.*/, 'index');
		$(this).text('Deleting...');
		$.post(this.href, function(data) {
			window.location.reload();
		});
		e.preventDefault();
	});
	
	$(document).ready(function () {
		setNavigation();
	});
	
	// fixed toolbar
	// $(window).scroll(function() {
		// if (this.scrollY > 69) {
			// $('.page-header').addClass('fixed-top');
		// } else {
			// $('.page-header').removeClass('fixed-top');
		// }
	// });
})(jQuery);

function setNavigation() {
    $(".left-nav a").each(function () {
        var href = $(this).attr('href');
        if (window.location == href) {
            $(this).closest('li').addClass('active');
        }
    });
}